#ifndef _CMOE_H_
#define _CMOE_H_

#include <stdint.h>

#define COUNTER_NAME_LEN 64
struct counter_t {
    char name[COUNTER_NAME_LEN];
    uint32_t count;
};
typedef struct counter_t counter_t;

#define SERVER_STRING "Server: CMoe Counter by Fumiama/1.0\r\n"

#define HTTP200 "HTTP/1.0 200 OK\r\n"
#define H400 "HTTP/1.0 400 BAD REQUEST\r\nContent-Type: text/html\r\n\r\n<P>%s\r\n"
#define H404 "HTTP/1.0 404 NOT FOUND\r\nContent-Type: text/html\r\n\r\n<HTML><TITLE>Not Found</TITLE>\r\n<BODY><P>%s\r\n</BODY></HTML>\r\n"
#define H500 "HTTP/1.0 500 Internal Server Error\r\nContent-Type: text/html\r\n\r\n<P>%s\r\n"
const static char* types[] = {H400, H404, H500};
const static uint8_t typel[] = {sizeof(H400)-2, sizeof(H404)-2, sizeof(H500)-2};
enum errcode_enum_t {HTTP400, HTTP404, HTTP500};
typedef enum errcode_enum_t errcode_enum_t;

#define CONTENT_TYPE(x) "Content-Type: " x "\r\n"
#define CONTENT_LEN "Content-Length: %d\r\n"
#define CACHE_CTRL "Cache-Control: max-age=0, no-cache, no-store, must-revalidate\r\n"

#define W_TINY 50
#define H_TINY 50
#define W_SMALL 45
#define H_SMALL 100
#define W_BIG 68
#define H_BIG 150

#define FLAG_BIG    (0b001)
#define FLAG_TINY   (0b010)
#define FLAG_SVG    (0b100)

#define SVG_DEFAULT_COLOR (0x5C5C66FF)

#define SVG_HEAD(h) \
                "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"%d\" height=\"" #h "\" version=\"1.1\">\n" \
                "  <title>Moe Count</title>\n" \
                "  <style xmlns=\"http://www.w3.org/2000/svg\">\n" \
                "    svg {\n" \
                "      image-rendering: pixelated;\n" \
                "    }\n" \
                "    @media (prefers-color-scheme: dark) { svg { filter: brightness(.6); } }\n" \
                "  </style>\n" \
                "  <g>\n"
const static char svg_tiny[] = SVG_HEAD(50);
const static char svg_small[] = SVG_HEAD(100);
const static char svg_big[] = SVG_HEAD(150);

const static char img_slot_front[] = "    <image x=\"%d\" width=\"%d\" height=\"%d\" xlink:href=\"";
const static char img_slot_rear[] = "\"></image>";

const static char svg_slot_front[] =
    "    <svg x=\"%d\" width=\"%d\" height=\"%d\" viewBox=\"0 0 1024 1024\">\n" \
    "      <path d=\"";
const static char svg_slot_rear[] =
    "\" fill=\"#%8X\"></path>\n" \
    "    </svg>";

const static char svg_tail[] = 
                "  </g>\n"
                "</svg>";

#define DEFINE_THEME(name, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9) \
    const static char* name[] = { s0, s1, s2, s3, s4, s5, s6, s7, s8, s9 }; \
    const static uint16_t name##l[] = { \
        sizeof(s0)-1, \
        sizeof(s1)-1, \
        sizeof(s2)-1, \
        sizeof(s3)-1, \
        sizeof(s4)-1, \
        sizeof(s5)-1, \
        sizeof(s6)-1, \
        sizeof(s7)-1, \
        sizeof(s8)-1, \
        sizeof(s9)-1 \
    };

DEFINE_THEME(mb,
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ""
);

DEFINE_THEME(mbh,
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ""
);

DEFINE_THEME(r34,
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ""
);

DEFINE_THEME(r3b,
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ""
);

DEFINE_THEME(gb,
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ""
);

DEFINE_THEME(gbh,
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ""
);

DEFINE_THEME(asl,
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ""
);

DEFINE_THEME(nix,
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ""
); // from https://commons.wikimedia.org/wiki/File:Nixie2.gif

DEFINE_THEME(mbs,
    "M802.27 157.73A317.89 317.89 0 0 0 576 64H448a320 320 0 0 0-320 320v256a320 320 0 0 0 320 320h128a320 320 0 0 0 320-320V384a317.89 317.89 0 0 0-93.73-226.27zM192 384c0-141.16 114.84-256 256-256h128c100.29 0 187.28 58 229.25 142.17A285.94 285.94 0 0 0 608 192H480a224 224 0 0 0-224 224v96c0 105.87 86.13 192 192 192h64a127.3 127.3 0 0 0 52.66-11.34A128.17 128.17 0 0 1 448 768h-32c-123.51 0-224-100.49-224-224z m256 192V448a64 64 0 0 1 128 0v128a64 64 0 0 1-128 0zM218.75 753.83A285.94 285.94 0 0 0 416 832h32c105.87 0 192-86.13 192-192V448a127.3 127.3 0 0 0-11.34-52.66A128.18 128.18 0 0 1 704 512v160c0 123.51-100.49 224-224 224h-32c-100.29 0-187.28-58-229.25-142.17zM832 640c0 100.29-58 187.28-142.17 229.25A285.94 285.94 0 0 0 768 672V512c0-105.87-86.13-192-192-192h-64a128.14 128.14 0 0 0-128 128v128a127.3 127.3 0 0 0 11.34 52.66A128.18 128.18 0 0 1 320 512v-96c0-88.22 71.78-160 160-160h128c123.51 0 224 100.49 224 224z",
    "M672 64H416a32 32 0 0 0-32 32 96.11 96.11 0 0 1-96 96 32 32 0 0 0-32 32v128a32 32 0 0 0 32 32h96v544a32 32 0 0 0 32 32h256a32 32 0 0 0 32-32V96a32 32 0 0 0-32-32z m-227.21 64H640v96.08A159.19 159.19 0 0 0 544 192H415.91a159.33 159.33 0 0 0 28.88-64zM448 384h64v512h-64z m192 512h-64V368a48.05 48.05 0 0 0-48-48H320v-64h224a96.11 96.11 0 0 1 96 96z",
    "M896 352v-64A224 224 0 0 0 672 64H160a32 32 0 0 0-32 32v256a32 32 0 0 0 32 32h314.43L158.81 752.21a128.1 128.1 0 0 0-30.81 83.3V928a32 32 0 0 0 32 32h704a32 32 0 0 0 32-32V672a32 32 0 0 0-32-32H674.58L889 372a32 32 0 0 0 7-20zM672 128a160.15 160.15 0 0 1 140.5 83.5A159 159 0 0 0 736 192H192v-64zM192 896v-60.49a64 64 0 0 1 15.41-41.65L558.72 384h75.7L295.7 779.17A32 32 0 0 0 320 832h512v64z m640-128H389.58l55-64.18a32 32 0 0 0 3.42 0.18h384zM499.29 640l229-267.17A32 32 0 0 0 704 320H192v-64h544a96.13 96.13 0 0 1 95.42 85.5L592.62 640z",
    "M830.39 129.61A222.53 222.53 0 0 0 672 64H160a32 32 0 0 0-32 32v256a32 32 0 0 0 32 32h352a32.05 32.05 0 0 1 30 20.78l-84.38 84.38-0.09 0.09-0.13 0.12a32 32 0 0 0-6 36.94l28.6 57.24V608a32 32 0 0 1-32 32H160a32 32 0 0 0-32 32v256a32 32 0 0 0 32 32h448a288 288 0 0 0 288-288 32 32 0 0 0-7-20L781.61 517.79 883.2 441.6A32 32 0 0 0 896 416V288a222.53 222.53 0 0 0-65.61-158.39zM672 128c73.16 0 135 49.35 154 116.51A207.12 207.12 0 0 0 688 192H192v-64zM448 704a96.17 96.17 0 0 0 91.38-66.56l36 45.07A96.14 96.14 0 0 1 480 768H192v-64zM192 896v-64h288c88.22 0 160-71.78 160-160a32 32 0 0 0-7-20L522.88 514.37l75.75-75.74A32 32 0 0 0 608 416a95.56 95.56 0 0 0-5.49-32H672a32 32 0 0 1 28.92 18.31L588.8 486.4c-0.27 0.2-0.54 0.39-0.8 0.6a32 32 0 0 0-5 45l121 151.23V688c0 114.69-93.31 208-208 208z m495-14.41c0.43-0.42 0.87-0.83 1.29-1.26A270.19 270.19 0 0 0 768 688v-16a32 32 0 0 0-7-20L653.61 517.79 755.2 441.6A32 32 0 0 0 768 416a96.11 96.11 0 0 0-96-96H192v-64h496c79.4 0 144 64.6 144 144l-115.2 86.4a32 32 0 0 0-6.4 44.8c0.2 0.27 0.42 0.52 0.62 0.78L831.74 682.9c-4.38 90.98-63.31 167.89-144.74 198.69z",
    "M928 448h-96V96a32 32 0 0 0-32-32H590.14a127.36 127.36 0 0 0-99.95 48L156.05 529.71a128.46 128.46 0 0 0-28.05 80v127.63a31.92 31.92 0 0 0 11 22.79 32.09 32.09 0 0 0 9.53 5.75h0.22A31.89 31.89 0 0 0 160 768h352v160a32 32 0 0 0 32 32h256a32 32 0 0 0 32-32V768h96a32 32 0 0 0 32-32V480a32 32 0 0 0-32-32zM192 609.67a64.27 64.27 0 0 1 14-40L540.17 152a63.66 63.66 0 0 1 50-24H640v448h-64V256a32 32 0 0 0-57-20L192 644.78zM457 576l55-68.77V576z m119 320V768h64v128z m320-192h-64v-64h64z m0-128h-96a32 32 0 0 0-32 32v288h-64V736a32 32 0 0 0-32-32H226.58L512 347.23v57.54L365.41 588a32 32 0 0 0 25 52H672a32 32 0 0 0 32-32V128h64v352a32 32 0 0 0 32 32h96z",
    "M873.52 65.44A31.89 31.89 0 0 0 864 64H160a32 32 0 0 0-32 32v329.34a224 224 0 0 0 123.82 200.35L280.45 640H160a32 32 0 0 0-32 32v256a32 32 0 0 0 32 32h448a288 288 0 0 0 288-288v-73.34a224 224 0 0 0-123.82-200.35L743.55 384H864a32 32 0 0 0 32-32V96a32 32 0 0 0-22.48-30.56zM832 128v64H192v-64zM192 425.34V256h640v64H288a32 32 0 0 0-32 32v79.11a111.1 111.1 0 0 0 61.42 99.38L536.45 640h-112.9l-143.1-71.55A159.13 159.13 0 0 1 192 425.34z m220.62-7.25L678 550.76A47.11 47.11 0 0 1 656.89 640h-18.33a51.49 51.49 0 0 0-27.18-34.09L346 473.24a46.84 46.84 0 0 1-26-42.13V384h65.44a51.49 51.49 0 0 0 27.18 34.09zM608 896H192v-64h480a222.38 222.38 0 0 0 122.87-36.64C754.74 856 686 896 608 896z m224-297.34V608c0 88.22-71.78 160-160 160H192v-64h464.89a111.11 111.11 0 0 0 49.69-210.49L487.56 384h112.89l143.1 71.55A159.13 159.13 0 0 1 832 598.66z",
    "M811.65 340.35A286.15 286.15 0 0 0 608 256h-68.77L575 104v-0.08l0.14-0.59A32 32 0 0 0 544 64H288a32 32 0 0 0-31.15 24.67l-128 544A32.27 32.27 0 0 0 128 640v32a288 288 0 0 0 288 288h192a288 288 0 0 0 288-288V544a286.15 286.15 0 0 0-84.35-203.65zM313.34 128h62.26L256.85 632.67A32.27 32.27 0 0 0 256 640v32a32 32 0 0 0 32 32h256a95.73 95.73 0 0 0 27.87-4.13A96.17 96.17 0 0 1 480 768H288a96.11 96.11 0 0 1-96-96v-28.29zM544 576a32 32 0 0 1 0 64h-95.17l15.09-64zM416 896a223.29 223.29 0 0 1-159.77-67.17A160.64 160.64 0 0 0 288 832h192c88.22 0 160-71.78 160-160v-64a95.73 95.73 0 0 0-4.13-27.87A96.17 96.17 0 0 1 704 672c0 123.51-100.49 224-224 224z m256-9.32q6-5.34 11.67-11A286.15 286.15 0 0 0 768 672c0-88.22-71.78-160-160-160H438.59a32 32 0 0 0-31.15 24.66L383.07 640h-62.2l120.47-512h62.26l-66 280.67A32 32 0 0 0 468.71 448H608c123.51 0 224 100.49 224 224 0 101.29-67.58 187.08-160 214.68z m139.65-418.33A286.15 286.15 0 0 0 608 384h-98.89l15.06-64H608c101.29 0 187.08 67.58 214.68 160q-5.34-5.93-11.03-11.65z",
    "M864 64H160a32 32 0 0 0-32 32v256a32 32 0 0 0 32 32h317.11a1121.38 1121.38 0 0 0-209.28 476.07l-11.31 62.21A32 32 0 0 0 288 960h256a32 32 0 0 0 31.24-25.06l2.76-12.29a1058.45 1058.45 0 0 1 241.56-472.49l44.11-49.62a127.88 127.88 0 0 0 32.33-85V96a32 32 0 0 0-32-32z m-32 64v64H192v-64zM330.79 871.52A1057.21 1057.21 0 0 1 558.84 384h74.89a1121.64 1121.64 0 0 0-242 502.35l-1.96 9.65h-63.43zM832 315.5a63.92 63.92 0 0 1-16.17 42.5l-44.11 49.62A1122.78 1122.78 0 0 0 518.41 896h-63.36a1057.65 1057.65 0 0 1 240.17-485.38l32.86-37.55A32 32 0 0 0 704 320H192v-64h640z",
    "M830.39 129.61A222.53 222.53 0 0 0 672 64H416a288 288 0 0 0-288 288 32 32 0 0 0 2.29 11.88L188 508.26l-54.67 82A32 32 0 0 0 128 608v128a224 224 0 0 0 224 224h320a224 224 0 0 0 224-224 31.92 31.92 0 0 0-1.64-10.12l-59.81-179.42 58.07-116.15A32 32 0 0 0 896 416V288a222.53 222.53 0 0 0-65.61-158.39zM672 128c73.16 0 135 49.35 154 116.51A207.12 207.12 0 0 0 688 192H544c-88.22 0-160 71.78-160 160a32 32 0 0 0 2.29 11.88L445.94 513l-28.3 84.88A31.92 31.92 0 0 0 416 608a95.56 95.56 0 0 0 5.49 32H352a32.06 32.06 0 0 1-31-23.88l57.39-86.07c0-0.06 0.07-0.12 0.11-0.17l0.09-0.13a31.92 31.92 0 0 0 3.09-29.63L320 345.84V336c0-114.69 93.31-208 208-208zM544 384a32.07 32.07 0 0 1 31.36 25.69l-60 120a31.93 31.93 0 0 0-1.74 24.43l24.24 72.7A32.07 32.07 0 0 1 512 640a32.05 32.05 0 0 1-31.71-27.68l30.06-90.19a31.81 31.81 0 0 0 0-20.25l-30.07-90.2A32.05 32.05 0 0 1 512 384zM337 142.42l-1.28 1.25A270.19 270.19 0 0 0 256 336v16a32 32 0 0 0 2.29 11.88L316 508.26l-54.67 82A32 32 0 0 0 256 608a96.11 96.11 0 0 0 96 96h160a95.77 95.77 0 0 0 47.41-12.57l16.3 48.89A32.05 32.05 0 0 1 544 768H336c-79.4 0-144-64.6-144-144v-6.31l58.43-87.64c0-0.06 0.07-0.12 0.11-0.17l0.09-0.13a31.92 31.92 0 0 0 3.09-29.63L192.08 346c2.45-93.09 62.01-172.22 144.92-203.58zM352 896c-73.16 0-135-49.35-154-116.51A207.12 207.12 0 0 0 336 832h208a96.11 96.11 0 0 0 96-96 31.92 31.92 0 0 0-1.64-10.12l-59.81-179.42 58.07-116.15A32 32 0 0 0 640 416a95.56 95.56 0 0 0-5.49-32H672a32.06 32.06 0 0 1 31.38 25.69l-60 120a31.93 31.93 0 0 0-1.74 24.43L704 741.19V752c0 79.4-64.6 144-144 144z m363.49-6A207.14 207.14 0 0 0 768 752v-16a31.92 31.92 0 0 0-1.64-10.12l-59.81-179.42 58.07-116.15A32 32 0 0 0 768 416a96.11 96.11 0 0 0-96-96H512a95.64 95.64 0 0 0-63.69 24.23A96.14 96.14 0 0 1 544 256h144c79.4 0 144 64.6 144 144v8.45l-60.62 121.24a31.86 31.86 0 0 0-1.73 24.45L831.92 741c-2.17 70.94-50.79 130.43-116.43 149z",
    "M811.65 148.35A286.15 286.15 0 0 0 608 64H416a288 288 0 0 0-288 288v128a288 288 0 0 0 288 288h68.77l-35.92 152.67A32 32 0 0 0 480 960h256a32 32 0 0 0 31.15-24.67l128-544A32.27 32.27 0 0 0 896 384v-32a286.15 286.15 0 0 0-84.35-203.65zM416 128h128c88.22 0 160 71.78 160 160v92.29L582.66 896H520.4l66-280.67a32 32 0 0 0-36.81-38.83 32.65 32.65 0 0 0-5.59-0.5H416a96 96 0 0 1-27.87-187.87A95.73 95.73 0 0 0 384 416v40a56.06 56.06 0 0 0 56 56h145.44a32 32 0 0 0 31.12-24.68l22.59-96A32.27 32.27 0 0 0 640 384v-64a128.14 128.14 0 0 0-128-128h-96a286.15 286.15 0 0 0-203.65 84.35q-5.7 5.7-11 11.67C228.92 195.58 314.71 128 416 128z m159.13 256l-15.06 64H448v-32a32 32 0 0 1 32-32zM416 704c-123.51 0-224-100.49-224-224s100.49-224 224-224h96a64.07 64.07 0 0 1 64 64H416c-88.22 0-160 71.78-160 160s71.78 160 160 160h98.89l-15.06 64z m416-323.71L710.66 896H648.4l118.75-504.67A32.27 32.27 0 0 0 768 384v-96a222.38 222.38 0 0 0-36.64-122.87C792 205.26 832 274 832 352z"
); // from https://www.iconfont.cn/collections/detail?cid=14920

#undef DEFINE_THEME

#endif
